import 'babel-polyfill';
import Vue from 'vue'
import app from './App'
import router from './router'
import store from './store'
import "./common/stylus/index.styl"
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import "../static/css/reset.css"

import sha256 from "js-sha256"
import md5 from 'js-md5';

Vue.use(ElementUI);
Vue.prototype.sha256 = sha256
Vue.prototype.md5 = md5

import axios from "axios"
Vue.prototype.axios = axios

import dtime from 'time-formater';
Vue.prototype.dtime = dtime
import screenfull from 'screenfull'
Vue.prototype.screenfull = screenfull
//上下轮播
import scroll from 'vue-seamless-scroll'
Vue.use(scroll)

//mixins
import {getSpanArr, toDecimal,getFileName,dateFtt,IEVersion,sortByKey} from "./store/mixins"
Vue.prototype.sortByKey = sortByKey
Vue.prototype.IEVersion = IEVersion
Vue.prototype.getSpanArr = getSpanArr
Vue.prototype.toDecimal = toDecimal
Vue.prototype.getFileName = getFileName
Vue.prototype.dateFtt = dateFtt
import util from "./store/utilJs"
Vue.prototype.makeSign = util.makeSign
Vue.prototype.signPw = util.signPw
Vue.prototype.unique = util.unique
// 签名等
axios.interceptors.request.use(
  config => {
    let sign
    if(config.method=='get'){
      let obj=util.getQueryData(config.url)
      sign=util.makeSign(obj)
      config.params={...config.params,sign:sign}
    }else if(config.timeout==20000){

    }else {
      let obj=config.data
      sign=util.makeSign(obj)
      config.data={...obj,sign:sign}
    }

    axios.defaults.headers.post['Content-Type'] = 'application/json';
    return config
  },function(error){
    return Promise.reject(error)
  }
)




//使用Echarts
// import 'echarts-gl'

import echarts from 'echarts'
Vue.prototype.echarts = echarts
//取消警告
Vue.config.productionTip = false


//路由拦截
router.beforeEach((to, from, next) => {
  if (to.name != "登录") {  // 判断该路由是否需要登录权限
    if (localStorage.getItem('isLogin')=="true") {  // 通过vuex state获取当前的token是否存在
      next();
    } else {
      next('/login')
      localStorage.clear()
    }
  } else {
    next();
  }

})

/*// 引入柱状图
 import 'echarts/lib/chart/bar';
 import 'echarts/lib/chart/line';
 import 'echarts/lib/chart/pictorialBar';
 import 'echarts/lib/component/title';
 import 'echarts/lib/component/legend';
 import 'echarts/lib/component/toolbox';
 import 'echarts/lib/component/markPoint';
 import 'echarts/lib/component/tooltip';*/


new Vue({
  el: '#app',
  render: h => h(app),
  router,
  store
})
